package com.ruoyi.ftrl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.ftrl.domain.DeviceBill;
import com.ruoyi.ftrl.service.IDeviceBillService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 设备台账管理Controller
 * 
 * @author dihang
 * @date 2025-04-29
 */
@RestController
@RequestMapping("/ftrl/bill")
public class DeviceBillController extends BaseController
{
    @Autowired
    private IDeviceBillService deviceBillService;

    /**
     * 查询设备台账管理列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:bill:list')")
    @GetMapping("/list")
    public TableDataInfo list(DeviceBill deviceBill)
    {
        startPage();
        List<DeviceBill> list = deviceBillService.selectDeviceBillList(deviceBill);
        return getDataTable(list);
    }
    /**
     * 根据供热类型查询子级热力站
     */
    @GetMapping("/names")
    public TableDataInfo names(String type) {
        List<String> names = deviceBillService.selectDeviceBillByType(type);
        // 使用 AjaxResult 包装 names
        return getDataTable(names);
    }

    /**
     * 导出设备台账管理列表
     */
    @PreAuthorize("@ss.hasPermi('ftrl:bill:export')")
    @Log(title = "设备台账管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, DeviceBill deviceBill)
    {
        List<DeviceBill> list = deviceBillService.selectDeviceBillList(deviceBill);
        ExcelUtil<DeviceBill> util = new ExcelUtil<DeviceBill>(DeviceBill.class);
        util.exportExcel(response, list, "设备台账管理数据");
    }

    /**
     * 获取设备台账管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('ftrl:bill:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return success(deviceBillService.selectDeviceBillById(id));
    }

    /**
     * 新增设备台账管理
     */
    @PreAuthorize("@ss.hasPermi('ftrl:bill:add')")
    @Log(title = "设备台账管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody DeviceBill deviceBill)
    {
        return toAjax(deviceBillService.insertDeviceBill(deviceBill));
    }

    /**
     * 修改设备台账管理
     */
    @PreAuthorize("@ss.hasPermi('ftrl:bill:edit')")
    @Log(title = "设备台账管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody DeviceBill deviceBill)
    {
        return toAjax(deviceBillService.updateDeviceBill(deviceBill));
    }

    /**
     * 删除设备台账管理
     */
    @PreAuthorize("@ss.hasPermi('ftrl:bill:remove')")
    @Log(title = "设备台账管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(deviceBillService.deleteDeviceBillByIds(ids));
    }
}
